﻿using System;
using System.Web;
using System.Web.UI;
using TS.Bussiness;
using TS.Commons;

namespace Tranco.UC
{
    public partial class MenuRight : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                VisiableMenu();
        }

        protected void lbtUser_Click(object sender, EventArgs e)
        {
            if (Session["TracoUserId"] != null)
            {

                Response.Redirect("~/Views/UserInfomation.aspx");
            }
            else
            {
                Response.Redirect("~/ErrorPermission.aspx");
            }
        }

        protected void lbtSchedule_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Views/ScheduleManagementOwner.aspx");
        }

        private void VisiableMenu()
        {
            UserBussiness bu = new UserBussiness();
            int userId = Session["TracoUserId"].ToNumeric();

            if (bu.GetRole(userId, "GatewayManagement.aspx") == null)
                gatewayList.Visible = false;
            else
            {
                gatewayList.Visible = true;
            }

            if (bu.GetRole(userId, "AddGateway.aspx") == null)
                gatewayAdd.Visible = false;
            else
            {
                gatewayAdd.Visible = true;
            }

            if (bu.GetRole(userId, "NumberBikeManagement.aspx") == null)
                numberBikeList.Visible = false;
            else
            {
                numberBikeList.Visible = true;
            }

            if (bu.GetRole(userId, "AddNumberBike.aspx") == null)
                numberBikeAdd.Visible = false;
            else
            {
                numberBikeAdd.Visible = true;
            }

            if (bu.GetRole(userId, "OwnerManagement.aspx") == null)
                ownerList.Visible = false;
            else
            {
                ownerList.Visible = true;
            }

            if (bu.GetRole(userId, "AddOwner.aspx") == null)
                ownerAdd.Visible = false;
            else
            {
                ownerAdd.Visible = true;
            }

            if (bu.GetRole(userId, "ScheduleManagement.aspx") == null)
                scheduleList.Visible = false;
            else
            {
                scheduleList.Visible = true;
            }


            if (bu.GetRole(userId, "AddSchedule.aspx") == null)
                scheduleAdd.Visible = false;
            else
            {
                scheduleAdd.Visible = true;
            }


            if (bu.GetRole(userId, "UserManagement.aspx") == null)
                userList.Visible = false;
            else
            {
                userList.Visible = true;
            }

            if (bu.GetRole(userId, "SignUp.aspx") == null)
                userAdd.Visible = false;
            else
            {
                userAdd.Visible = true;
            }

            if (bu.GetRole(userId, "GroupPermission.aspx") == null)
                roleAdd.Visible = false;
            else
            {
                roleAdd.Visible = true;
            }

            if (bu.GetRole(userId, "Config.aspx") == null)
                cofigAdd.Visible = false;
            else
            {
                cofigAdd.Visible = true;
            }

            if (bu.GetRole(userId, "CloseWebsiteManagement.aspx") == null)
                closedWebsite.Visible = false;
            else
            {
                closedWebsite.Visible = true;
            }

            if (gatewayList.Visible == false && gatewayAdd.Visible == false)
                liGateway.Visible = false;

            if (numberBikeAdd.Visible == false && numberBikeList.Visible == false)
                liNumberBike.Visible = false;

            if (ownerList.Visible == false && ownerAdd.Visible == false)
                liOwner.Visible = false;

            if (scheduleAdd.Visible == false && scheduleList.Visible == false)
                liSchedule.Visible = false;


            if (userList.Visible == false && userAdd.Visible == false)
                liUser.Visible = false;

            if (cofigAdd.Visible == false && roleAdd.Visible == false && closedWebsite.Visible == false)
                liConfig.Visible = false;
        }

    }
}